# -*- coding: utf-8 -*-
import logging
from datetime import datetime

def save_log(name, err):
    # 配置日志输出格式
    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    logger = logging.getLogger()
    logger.setLevel(logging.ERROR)
    console_handler = logging.StreamHandler()
    console_handler.setLevel(logging.ERROR)
    console_handler.setFormatter(formatter)
    logger.addHandler(console_handler)
    filename = "error_" + datetime.now().strftime('%Y%m%d') + ".log"
    file_handler = logging.FileHandler(filename)
    file_handler.setLevel(logging.ERROR)
    file_handler.setFormatter(formatter)
    logger.addHandler(file_handler)

    logger.error(name + " : {}".format(err))


